package com.mytest.leetcode;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by shixi  on 2019/6/24
 */
@Slf4j
public class Solution226 {

    public static void main(String[] args) {
        Solution226 solution = new Solution226();

        TreeNode root = new TreeNode(5);

        TreeNode left = new TreeNode(4);
        TreeNode right = new TreeNode(8);

        TreeNode node_11 = new TreeNode(11);
        TreeNode node_7 = new TreeNode(7);
        TreeNode node_2 = new TreeNode(2);


        TreeNode node_13 = new TreeNode(13);
        TreeNode node_4 = new TreeNode(4);
        TreeNode node_1 = new TreeNode(1);

        root.left = left;
        root.right = right;


        left.left = node_11;
        node_11.left = node_7;
        node_11.right = node_2;

        right.left = node_13;
        right.right = node_4;

        node_4.right = node_1;

        log.info("{}", root);
        TreeNode result = solution.invertTree(root);
        log.info("{}", result);

    }

    public TreeNode invertTree(TreeNode root) {
        if(root== null){
            return null;
        }
        TreeNode result = new TreeNode(root.val);

        TreeNode left = invertTree(root.right);
        TreeNode right = invertTree(root.left);
        result.left = left;
        result.right = right;
        return result;
    }
}

